﻿using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using Teigha.Core;

namespace Teigha.TD
{
	public class OdPwdIterator : OdRxObject
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public OdPwdIterator(IntPtr cPtr, bool cMemoryOwn) : base(TD_DbPINVOKE.OdPwdIterator_SWIGUpcast(cPtr), cMemoryOwn)
		{
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(OdPwdIterator obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~OdPwdIterator()
		{
			this.Dispose();
		}

		public override void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							TD_DbPINVOKE.delete_OdPwdIterator(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
			base.Dispose();
		}

		public virtual bool done()
		{
			bool result = TD_DbPINVOKE.OdPwdIterator_done(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public virtual void next()
		{
			TD_DbPINVOKE.OdPwdIterator_next(this.swigCPtr);
			if (TD_DbPINVOKE.SWIGPendingException.Pending)
			{
				throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public virtual void get(ref string password)
		{
			IntPtr intPtr = Marshal.StringToCoTaskMemUni(password);
			IntPtr value = intPtr;
			try
			{
				TD_DbPINVOKE.OdPwdIterator_get(this.swigCPtr, ref intPtr);
				if (TD_DbPINVOKE.SWIGPendingException.Pending)
				{
					throw TD_DbPINVOKE.SWIGPendingException.Retrieve();
				}
			}
			finally
			{
				if (intPtr != value)
				{
					password = Marshal.PtrToStringUni(intPtr);
				}
			}
		}

		private object locker = new object();

		private HandleRef swigCPtr;
	}
}
